package com.ysp;

/**
 * @author ysp
 * @date 2021/1/9 16:52
 */
public class Person {

    private String name;
    private int id;
    private char gender;
    private String number;
    private String address;

    private Person(){}

    /**
     * 这里使用的是静态内部类做为person的建造者
     */
    public static class PersonBuilder{
        //维护一个person对象
        Person person = new Person();

        //这里可以使用接口，规范不同的构建部分需要完成的事情，使用PersonBuilder作为返回值是利于链式编程
        public PersonBuilder basic(int id,String name,char gender){
            person.id = id;
            person.name = name;
            person.gender = gender;
            return this;
        }
        public PersonBuilder number(String number){
            person.number = number;
            return this;
        }
        public PersonBuilder address(String address){
            person.address = address;
            return this;
        }
        //这个方法是用于返回构建的对象实例
        public Person builder(){
            return person;
        }
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", id=" + id +
                ", gender=" + gender +
                ", number='" + number + '\'' +
                ", address='" + address + '\'' +
                '}';
    }
}
